/* Init control for buttons in action panel */
$("#searchButton").control({
    type: FD_PANEL_CONTROL, 
    panel: "#search-panel"
});
$("#accountButton").control({
    type: FD_PANEL_CONTROL, 
    panel: "#login-panel"
});
$("#settingButton").control({
    type: FD_PANEL_CONTROL, 
    panel: "#language-panel"
});
$("input[name='language']").control({
    type: LANGUAGE_CONTROL
});
$(".sign-in").click(function(){
    $(this).login({
        email: $("#txt-email").val(),
        password: $("#txt-password").val(),
        loginUrl: $("#login-form").attr('action')
    });
});
$("#txt-password").keypress(function(e) {
    if(e.which == 13) {
        $(".sign-in").login({
            email: $("#txt-email").val(),
            password: $("#txt-password").val(),
            loginUrl: $("#login-form").attr('action')
        });
    }
});
$("#txt-email").keypress(function(e) {
    if(e.which == 13) {
        $(".sign-in").login({
            email: $("#txt-email").val(),
            password: $("#txt-password").val(),
            loginUrl: $("#login-form").attr('action')
        });
    }
});
$("#btn-close").click(function(){
    $(".errorMsg").text("");
    $("#modal-dialog").hide();
});
/* search handler */
$("#search-content").keypress(function(e) {
    if(e.which == 13) {
        $("#search-content").search();
    }
});
$("#submit-search").click(function(){
    $("#search-content").search();     
});
$(window).resize(function(){
    $('.dialog').css("margin-top", -$('.dialog').height()/2 + "px");
});
document.addEventListener('touchmove', function (e) {
    e.preventDefault();
}, false);
document.addEventListener('DOMContentLoaded', function(){
    mainScroll = new iScroll('wrapper', {
        useTransform: false,
        hScrollbar: false,
        vScrollbar: false,
        onBeforeScrollStart: function (e) {
            var target = e.target;
            while (target.nodeType != 1) target = target.parentNode;

            if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA' && target.tagName != 'P')
                e.preventDefault();
        }
    });
}, false);
$("#wrapper").everyTime(1000, function (i) {
    mainScroll.refresh();
}, 0);